package com.chb.microservice.provider.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cbh.api.model.ApiResult;
import com.chb.microservice.provider.hystrix.ProductHystrixWrapped;
import com.chb.microservice.provider.model.Product;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RefreshScope
@Api(description = "产品管理")
@RestController
@RequestMapping("/sign/v3/products")
public class ProductController {
	@Autowired
	ProductHystrixWrapped productHystrixWrapped;

	/**
	 * 保存产品信息
	 * 
	 * @param product
	 * @return
	 */
	@ApiOperation(value = "产品信息保存", httpMethod = "POST")
	@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json")
	public ApiResult<String> save(@ApiParam(value = "产品信息", required = true) @RequestBody(required = true) Product ob) {
		return productHystrixWrapped.save(ob);
	}

	/**
	 * 获取全部产品信息
	 * 
	 * @return
	 */
	@ApiOperation(value = "获取全部产品信息", httpMethod = "GET")
	@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<List<Product>> getAll() {
		return productHystrixWrapped.getAll();
	}

	/**
	 * 获取产品信息
	 * 
	 * @param proId
	 * @return
	 */
	@ApiOperation(value = "获取产品信息", httpMethod = "GET")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", dataType = "String", required = true) })
	@RequestMapping(value = "{id}", method = RequestMethod.GET, produces = "application/json")
	public ApiResult<Product> getOne(@PathVariable("id") String id) {
		return productHystrixWrapped.getOne(id);
	}
}
